<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>Currency Converter Administration</title>
    </h:head>
    <h:body>
        <h1>Currency Converter Administration</h1>

        <h:form>
            <h:commandLink id="link" action="goToConverterPage">
                <h:outputText value="Go back to converter"/>
            </h:commandLink>
            
            <p>
                <h3 style="color: red">
                    <c:choose>
                        <c:when test="#{currencyManager.exception.cause != null}">
                            <h:outputText value="Error. Cause: #{currencyManager.exception.cause.message}" rendered="#{!currencyManager.success}" />
                        </c:when>
                        <c:otherwise>
                            <h:outputText value="Error: #{currencyManager.exception.message}" rendered="#{!currencyManager.success}" />
                        </c:otherwise>                            
                    </c:choose>
                </h3>         
            </p>
        </h:form>

        <h:form rendered="#{currencyManager.loggedIn}">
            <p>
                <h:outputLabel rendered="#{currencyManager.loggedIn}"  value="Welcome, admin."/>
            </p>
            
            <h3>Add new currency</h3>
            <p>
                <h:outputLabel for="symbol"  value="Currency symbol:"/>
                <h:inputText id="symbol" value="#{currencyManager.symbol}"/>
            </p>
            <p>
                <h:outputLabel for="country" value="Currency country:"/>
                <h:inputText id="country" value="#{currencyManager.country}"/>
            </p>
            <p>
                <h:outputLabel for="name" value="Currency name:"/>
                <h:inputText id="name" value="#{currencyManager.currencyName}"/>
            </p>
            <p>
                <h:commandButton value="Create" action="#{currencyManager.createCurrency}"/>
            </p>
        </h:form>

        <h:form rendered="#{currencyManager.loggedIn}">
            <h3>Change exchange rate</h3>
            <p>
                <h:outputLabel for="from"  value="From:"/>
                <h:selectOneMenu id ="from" value="#{currencyManager.fromCurrencyStr}">
                    <f:selectItems value="#{currencyManager.currencies}"/>
                </h:selectOneMenu>
            </p>
            <p>
                <h:outputLabel for="to" value="To:"/>
                <h:selectOneMenu id="to" value="#{currencyManager.toCurrencyStr}">
                    <f:selectItems value="#{currencyManager.currencies}"/>
                </h:selectOneMenu>
            </p>
            <p>
                <h:outputLabel for="rate" value="Rate:"/>
                <h:inputText id="rate" value="#{currencyManager.rate}"/>
            </p>
            <p>
                <h:commandButton value="Change" action="#{currencyManager.changeRate}"/>
            </p>
        </h:form>

        <h:form rendered="#{!currencyManager.loggedIn}">
            <h1>Login</h1>
            <p>
                <h:outputLabel for="userName" rendered="#{!currencyManager.loggedIn}"  value="User name: "/>
                <h:inputText id="userName" value="#{currencyManager.userName}"/>
            </p>
            <p>
                <h:outputLabel for="pwd" rendered="#{!currencyManager.loggedIn}"  value="Password: "/>
                <h:inputSecret id="pwd" value="#{currencyManager.password}"/>
            </p>
            <p>
                <h:commandButton value="Log in" action="#{currencyManager.login}"/>
            </p>
        </h:form>
    </h:body>
</html>

